var ApprovalWarehouseByReturnToProvider = function () {
  var template = /*html*/ `
    <div class="ApprovalWarehouseByReturnToProvider" v-loading.fullscreen.lock="loading">
      <div>
        <search-btn-view immediate btn-text="查询条件" @before-open="resetSearch" @search="searchData">
          <div slot="search-content">
            <sys-common-search request-url="materialSelectFilter/getMaterialSelectData" :request-data="{type:19}"
              :search="search" :search-field="searchField" label-width="100px" input-width="180px">
              <template slot="prepend">
                <el-form-item label="制单日期">
                  <el-date-picker v-model="search.startDate" style="width:229px;" value-format="timestamp" :editable="false"
                    :picker-options="startDateOption" placeholder="制单开始日期"></el-date-picker>
                  -
                  <el-date-picker v-model="search.endDate" style="width:229px;" value-format="timestamp" :editable="false"
                    :picker-options="endDateOption" placeholder="制单结束日期"></el-date-picker>
                </el-form-item>
              </template>
              <template slot="append">
                <el-form-item label="单据状态">
                  <el-select clearable v-model="search.status" placeholder="请选择单据状态" style="width:180px">
                    <el-option v-for="status in statusList" :key="'status_'+status.value" :value="status.value"
                      :label="status.label"></el-option>
                  </el-select>
                </el-form-item>
              </template>
            </sys-common-search>
          </div>
        </search-btn-view>
      </div>
      <div class="returnToProvider-mgr-table-div">
        <el-table fit stripe border :data="returnMaterialToProviderData" highlight-current-row style="width:100%;" height="parent">
          <el-table-column sortable prop="companyOrderId" label="订单编号" min-width="140px" header-align="center"></el-table-column>
          <el-table-column sortable prop="orderId" label="系统订单编号" min-width="140px" header-align="center"></el-table-column>
          <el-table-column sortable prop="factoryNo" label="工厂型号" min-width="120px" header-align="center"></el-table-column>
          <el-table-column sortable prop="coustomId" label="客户型号" min-width="120px" header-align="center"></el-table-column>

          <el-table-column sortable prop="providerName" label="供应商" min-width="100px" header-align="center"></el-table-column>
          <el-table-column sortable prop="materialName" label="物料名称" min-width="130px" header-align="center"></el-table-column>
          <el-table-column sortable prop="color" label="编号" min-width="100px" header-align="center"></el-table-column>
          <el-table-column sortable prop="colorDescription" label="描述" min-width="120px" header-align="center"></el-table-column>
          <el-table-column sortable prop="model" label="规格" min-width="120px" header-align="center"></el-table-column>
          <el-table-column sortable prop="materialDeptName" label="物料部门" min-width="120px" align="center"></el-table-column>

          <el-table-column sortable prop="inOutUnit" label="单位" min-width="90px" align="center"></el-table-column>
          <el-table-column sortable prop="inCountPrice" label="单价" min-width="120px" align="center"></el-table-column>
          <el-table-column sortable prop="count" label="数量" min-width="120px" align="center"></el-table-column>
          <el-table-column sortable prop="sumMoneyCount" label="结算数量" min-width="120px" align="center"></el-table-column>

          <el-table-column sortable prop="createUser" label="制单人" min-width="100px" header-align="center">
          </el-table-column>
          <el-table-column sortable :resizable="false" prop="createTime" label="制单时间" width="90px" align="center">
          </el-table-column>
          <el-table-column sortable :resizable="false" prop="status" label="状态" width="90px" align="center">
            <template slot-scope="scope">
              <span>{{i18n.getMsg('returnOrder.status.'+scope.row.status)}}</span>
            </template>
          </el-table-column>
          <el-table-column sortable prop="approvalUser" label="审核人" min-width="120px" header-align="center">
          </el-table-column>
          <el-table-column sortable :resizable="false" prop="approvalTime" label="审核时间" width="90px" align="center"></el-table-column>

          <el-table-column :resizable="false" label="操作" width="95px" fixed="right" header-align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.status===0&&scope.row.isApperval===1">
                <el-button type="primary" size="mini" style="padding-left:7px;padding-right:7px;"
                  @click="approval(scope.row,1)">审核</el-button>
                <el-button type="danger" size="mini" style="padding-left:7px;padding-right:7px;margin-left:0;"
                  @click="approval(scope.row,2)">退回</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <table-pagination v-if="pagination.totalCount!==0" :pagination="pagination" @change="pageChange"></table-pagination>
    </div>
  `;
  return {
    mixins: [
      tablePaginationMixin(),
      datePickerOptionsMixin('startDate','endDate')
    ],
    data: function () {
      var search = {
        materialName: '',
        model: '',
        color: '',
        colorDescription: '',
        providerName: '',
        materialDept: '',
        companyOrderId: '',
        orderId: '',
        factoryNo: '',
        customerNo: '',
        status: '',
        startDate: null,
        endDate: null
      };
      return {
        loading: false,
        moment: moment,
        returnMaterialToProviderData: [],
        search: _.cloneDeep(search),
        oldSearch: _.cloneDeep(search),
        searchField: ['materialName', 'model', 'color', 'providerName', 'materialDept', 'orderId', 'companyOrderId', 'factoryNo', 'customerNo'],
        statusList: i18n.getDropDown('returnOrder.status', [0, 1, 2]),
        i18n: i18n,
        pagination: {
          currentPage: 1,
          totalCount: 0,
          pageSize: 10
        }
      }
    },
    methods: {
      resetSearch: function () {
        this.search = _.cloneDeep(this.oldSearch);
      },
      searchData: function () {
        this.pagination.currentPage = 1;
        this.setMaterialDataList(true);
      },
      pageChange: function () {
        this.setMaterialDataList();
      },
      setMaterialDataList: function (isSearch) {
        if (!isSearch) {
          this.search = _.cloneDeep(this.oldSearch);
        }
        var search = this.search;
        var pagination = this.pagination;
        var currentPage = pagination.currentPage;
        var pageSize = pagination.pageSize;
        var start = (currentPage - 1) * pageSize;
        var postData = {
          start: start,
          length: pageSize
        }
        postData = this.setPostData(postData, search);
        this.loading = true;
        var self = this;
        ajaxRequest("returnWarehouseToProvider/getInCountByReturnToProvderData", postData, false).then(function (res) {
          if (isSearch) {
            self.oldSearch = _.cloneDeep(self.search);
          }
          var dataList = res.returnData;
          for (var i = 0; i < dataList.length; i++) {
            var data = dataList[i];
            SysUtil.tableSetDeptData(data);
          }
          self.returnMaterialToProviderData = dataList;
          self.pagination.totalCount = res.iTotalRecords;
          self.loading = false;
        }).catch(function () {
          self.loading = false;
        });
      },
      setPostData: function (postData, search) {
        var fields = ['orderId', 'companyOrderId', 'factoryNo', 'customerNo', 'materialName', 'model', 'color',
          'colorDescription', 'providerName', 'status'
        ];
        SysUtil.setPostData(postData, search, fields);

        var materialDept = search.materialDept;
        if (materialDept !== '') {
          postData.materialDeptId = materialDept.materialDeptId;
        }

        var startDate = search.startDate;
        if (startDate !== null) {
          postData.startDate = moment(startDate).format('YYYY-MM-DD');
        }

        var endDate = search.endDate;
        if (endDate !== null) {
          postData.endDate = moment(endDate).format('YYYY-MM-DD');
        }
        return postData;
      },
      approval: function (data, status) {
        this.loading = true;
        var self = this;
        ajaxRequest("returnWarehouseToProvider/updateInCountByReturnToProvderData", {
          id: data.id,
          status: status
        }).then(function (res) {
          self.$alert(res, "信息");
          self.setMaterialDataList();
        }).catch(function () {
          self.loading = false;
        });
      }
    },

    components: {
      SearchBtnView: SearchBtnView,
      SysCommonSearch: SysCommonSearch
    },

    template: template
  }
}();
